package com.yh.threadTest.test2;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName Demo3
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/11/12 11:14
 */
public class Demo4 {

    public static void main(String[] args) throws InterruptedException {
        Long aiShare = new Long(0);
        List<Thread> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(new Accumlator2(aiShare));
            list.add(t);
            t.start();
        }
        for (Thread t : list) {
            t.join();
        }

        System.out.println(aiShare);
    }
}

class Accumlator2 implements Runnable {

    private Long ai;

    public Accumlator2(Long ai) {
        this.ai = ai;
        System.out.println(ai.getClass());
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            ai++;
        }
    }
}
